//Copyright 2008, 2009, 2010 Miguel Ángel Laguna Lobato
//
//This file is part of Multiclinical Trial Web-PACS.
//
//Multiclinical  Trial Web-PACS is free  software: you  can redistribute 
//it and/or modify it under  the terms of the GNU General Public License 
//as published by the Free  Software Foundation, either version 3 of the 
//License, or (at your option) any later version.
//
//Multiclinical  Trial Web-PACS is distributed  in the hope that it will 
//be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 
//of  MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
//General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with Multiclinical Trial Web-PACS.  If not, see 
//<http://www.gnu.org/licenses/>.

package es.urjc.mctwp.modelo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

// Generated 28-may-2007 20:48:40 by Hibernate Tools 3.2.0.b9

/**
 * Rol generated by hbm2java
 */
public class Rol extends DomainObject implements java.io.Serializable {

	private static final long serialVersionUID = 2768373443469199148L;
	private String name;
	private Set<Participation> Participations = null;
	private Set<Action> actions = null;

	public Rol() {
	}

	public String getName() {
		return this.name;
	}

	public void setName(String nombre) {
		this.name = nombre;
	}

	public void setActions(Set<Action> acciones) {
		this.actions = acciones;
	}

	public Set<Action> getActions() {
		return actions;
	}
	
	public List<Action> getActionsSorted(){
		List<Action> result = null;
		
		if(actions != null){
			result = new ArrayList<Action>(actions);
			Collections.sort(result);
		}
		
		return result;
	}
	
	/**
	 * Convenience method for stablish correctly relationship between 
	 * rol and action.
	 *  
	 * @param action
	 */
	public void addAction(Action action){
		if(action != null){
			if(actions == null)
				actions = new HashSet<Action>();
			
			actions.add(action);
			action.addRol(this);
		}
	}

	/**
	 * Convenience method for remove correctly relationship between 
	 * rol and action.
	 *  
	 * @param action
	 */
	public void delAction(Action action){
		if(action != null){
			if(actions != null){
				actions.remove(action);
				action.delRol(this);
			}
		}
	}

	public void setParticipations(Set<Participation> participaciones) {
		this.Participations = participaciones;
	}

	public Set<Participation> getParticipations() {
		return Participations;
	}

}
